package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
/**
 * 统计报表服务
 */
public class ReportServiceImpl implements ReportService {
    @Autowired
    //会员dao
    private MemberDao memberDao;
    @Autowired
    //体检预约dao
    private OrderDao orderDao;

    @Override
    public Map<String, Object> getBusinessReport() throws Exception {
        //获得当前日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获得本周一的日期
        String thisweekmonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获得本月第一天的日期
        String firstdaythismonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //获取今日增加会员数
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        //总会员数
        Integer count = memberDao.findMemberTotalCount();
        //本周新增会员数
        Integer thisweekNewMember = memberDao.findMemberCountAfterDate(thisweekmonday);
        //本月新增会员数
        Integer thisMonthNewMember =memberDao.findMemberCountAfterDate(firstdaythismonth);
        //今日预约数
        Integer  todayOrderNumber =orderDao.findOrderCountByDate(today);
        //本周预约数
        Integer thisWeekOrderNumber =orderDao.findOrderCountAfterDate(thisweekmonday);
        //本月预约数
        Integer thisMonthOrderNumber=orderDao.findOrderCountAfterDate(firstdaythismonth);
        //今日到诊数
        Integer todayVisitsNumber =orderDao.findVisitsCountByDate(today);
        //本周到诊数
        Integer thisWeekVisitsNumber =orderDao.findVisitsCountAfterDate(thisweekmonday);
        //本月到诊数
        Integer thisMonthVisitsNumber =orderDao.findVisitsCountAfterDate(firstdaythismonth);
        //热门套餐
        List<Map> list=orderDao.findHotSetmeal();
        Map<String, Object> map=new HashMap<>();
        map.put("reportDate",today);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",count);
        map.put("thisWeekNewMember",thisweekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",list);
        return map;
    }
}
